package com.ruoyi.sale.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.sale.domain.SaleReturnDetail;
import com.ruoyi.sale.service.ISaleReturnDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 退货单详情Controller
 * 
 * @author ruoyi
 * @date 2022-09-03
 */
@RestController
@RequestMapping("/returnDetail")
public class SaleReturnDetailController extends BaseController
{
    @Autowired
    private ISaleReturnDetailService saleReturnDetailService;

    /**
     * 查询退货单详情列表
     */
    @RequiresPermissions("sale:returnDetail:list")
    @GetMapping("/list")
    public TableDataInfo list(SaleReturnDetail saleReturnDetail)
    {
        startPage();
        List<SaleReturnDetail> list = saleReturnDetailService.selectSaleReturnDetailList(saleReturnDetail);
        return getDataTable(list);
    }

    /**
     * 导出退货单详情列表
     */
    @RequiresPermissions("sale:returnDetail:export")
    @Log(title = "退货单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SaleReturnDetail saleReturnDetail)
    {
        List<SaleReturnDetail> list = saleReturnDetailService.selectSaleReturnDetailList(saleReturnDetail);
        ExcelUtil<SaleReturnDetail> util = new ExcelUtil<SaleReturnDetail>(SaleReturnDetail.class);
        util.exportExcel(response, list, "退货单详情数据");
    }

    /**
     * 获取退货单详情详细信息
     */
    @RequiresPermissions("sale:returnDetail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(saleReturnDetailService.selectSaleReturnDetailById(id));
    }

    /**
     * 新增退货单详情
     */
    @RequiresPermissions("sale:returnDetail:add")
    @Log(title = "退货单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SaleReturnDetail saleReturnDetail)
    {
        return toAjax(saleReturnDetailService.insertSaleReturnDetail(saleReturnDetail));
    }

    /**
     * 修改退货单详情
     */
    @RequiresPermissions("sale:returnDetail:edit")
    @Log(title = "退货单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SaleReturnDetail saleReturnDetail)
    {
        return toAjax(saleReturnDetailService.updateSaleReturnDetail(saleReturnDetail));
    }

    /**
     * 删除退货单详情
     */
    @RequiresPermissions("sale:returnDetail:remove")
    @Log(title = "退货单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(saleReturnDetailService.deleteSaleReturnDetailByIds(ids));
    }
}
